<%--
  Created by IntelliJ IDEA.
  User: kwc13
  Date: 2022/7/24
  Time: 22:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script>
    <c:if test="${name != null}">
    var name = "${name}";
    if (name != "登陆"){
        var mysqlname = document.getElementsByClassName("mysqlname")
        mysqlname[0].innerText = name;
        mysqlname[0].href = "/personal/order"
        var notification = document.getElementsByClassName("notification")
        notification[0].innerText = "消息通知";
        notification[0].href = "#"
        var information = document.getElementsByClassName("information")
        information[0].style.width = "310px";
        information[0].style.marginLeft = "-120px"
        var nameRow = document.getElementsByClassName("nameRow")
        nameRow[0].style.width = "120px"
        var order = document.getElementsByClassName("order")
        order[0].innerText = "我的订单"
    }
    </c:if>



    <c:if test="${size != null}">
    <%
    String size = String.valueOf(request.getAttribute("size"));
    String numbering = "commodity";
    StringBuffer all = new StringBuffer();
    for (int i = 0; i < Integer.parseInt(size); i++) {
      all.append("|"+request.getAttribute(numbering+i));
    }
    request.setAttribute("all",all);
  %>

    var all = "${all}"
    var bars = all.split("|");
    var titles = 0;
    for (let i = 1; i < bars.length+1; i++) {
        if (bars[i] != undefined){
            var data = bars[i].split(",");
        }
        if (data[9] == "路由器"){
            titles = 7 ;
            var img = document.getElementsByClassName("img"+titles);
            var nameText = document.getElementsByClassName("name"+titles);
            var price = document.getElementsByClassName("price"+titles);
            for (let i = 0; i < img.length; i++) {
                if (img[i].getAttribute("state") == "false"){
                    img[i].src = data[4]
                    nameText[i].innerText = data[1]
                    price[i].innerText = data[3]+"元起"
                    img[i].setAttribute("state","true")
                    break
                }
            }
        }else if (data[9] == "手机"){
            var introduction_Img = document.getElementsByClassName("introduction_Img")
            if (data[7] == "小米"){
                titles = 1 ;
                var img = document.getElementsByClassName("img"+titles);
                var nameText = document.getElementsByClassName("name"+titles);
                var price = document.getElementsByClassName("price"+titles);
                for (let i = 0; i < img.length; i++) {
                    if (img[i].getAttribute("state") == "false"){
                        img[i].src = data[4]
                        nameText[i].innerText = data[1]
                        price[i].innerText = data[3]+"元起"
                        img[i].setAttribute("state","true")
                        break
                    }
                }
            }else if (data[7] == "红米"){
                titles = 2 ;
                var img = document.getElementsByClassName("img"+titles);
                var nameText = document.getElementsByClassName("name"+titles);
                var price = document.getElementsByClassName("price"+titles);
                for (let i = 0; i < img.length; i++) {
                    if (img[i].getAttribute("state") == "false"){
                        img[i].src = data[4]
                        nameText[i].innerText = data[1]
                        price[i].innerText = data[3]+"元起"
                        img[i].setAttribute("state","true")
                        break
                    }
                }
            }
        }else if (data[9] == "电视"){
            titles = 3 ;
            var img = document.getElementsByClassName("img"+titles);
            var nameText = document.getElementsByClassName("name"+titles);
            var price = document.getElementsByClassName("price"+titles);
            for (let i = 0; i < img.length; i++) {
                if (img[i].getAttribute("state") == "false"){
                    img[i].src = data[4]
                    nameText[i].innerText = data[1]
                    price[i].innerText = data[3]+"元起"
                    img[i].setAttribute("state","true")
                    break
                }
            }
        }else if (data[9] == "笔记本"){
            titles = 4 ;
            var img = document.getElementsByClassName("img"+titles);
            var nameText = document.getElementsByClassName("name"+titles);
            var price = document.getElementsByClassName("price"+titles);
            for (let i = 0; i < img.length; i++) {
                if (img[i].getAttribute("state") == "false"){
                    img[i].src = data[4]
                    nameText[i].innerText = data[1]
                    price[i].innerText = data[3]+"元起"
                    img[i].setAttribute("state","true")
                    break
                }
            }
        }else if (data[9] == "平板"){
            titles = 5 ;
            var img = document.getElementsByClassName("img"+titles);
            var nameText = document.getElementsByClassName("name"+titles);
            var price = document.getElementsByClassName("price"+titles);
            for (let i = 0; i < img.length; i++) {
                if (img[i].getAttribute("state") == "false"){
                    img[i].src = data[4]
                    nameText[i].innerText = data[1]
                    price[i].innerText = data[3]+"元起"
                    img[i].setAttribute("state","true")
                    break
                }
            }
        }else if(data[9] == "家电"){
            titles = 6 ;
            var img = document.getElementsByClassName("img"+titles);
            var nameText = document.getElementsByClassName("name"+titles);
            var price = document.getElementsByClassName("price"+titles);
            for (let i = 0; i < img.length; i++) {
                if (img[i].getAttribute("state") == "false"){
                    img[i].src = data[4]
                    nameText[i].innerText = data[1]
                    price[i].innerText = data[3]+"元起"
                    img[i].setAttribute("state","true")
                    break
                }
            }
        }
    }
    </c:if>
</script>
